package com.vion.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author vion
 **/
@Component
@Slf4j
public class KafkaProducerDemo {

    @Resource
    private KafkaTemplate kafkaTemplate;
    @Value("${test.data.switch:0}")
    private String testDataSwitch;


    @Scheduled(cron = "0/5 * * * * ? ")
    public void vehicleTestData(){
        if("0".equals(testDataSwitch)){
            return;
        }
        Map<String,String> map = new HashMap<>();
        map.put("gcsj","2022-01-01 15:00:00.000");
        kafkaTemplate.send("vehicleData",map);
        log.info("发送过车测试数据成功");
    }

    @Scheduled(cron = "0/5 * * * * ? ")
    public void illegalTestData(){
        if("0".equals(testDataSwitch)){
            return;
        }
        Map<String,String> map = new HashMap<>();
        map.put("cjsj","2021-01-01 00:00:00.000");
        kafkaTemplate.send("illegalData",map);
        log.info("发送违法测试数据成功");
    }

}